<template>
	<div>
		<ApplyReport :nowRowData="nowData" :isPigeonhole="true" :creditCode="params.creditCode" :params="params" :custome="true" :isDetail="true" v-if="!loading" :navTagList="navTagList">
			<el-scrollbar max-height="50vh">
				<div class="progress-box">
					<div class="time-line">
						<div class="time-line-item" v-for="(item, index) in lineTimeList" :key="index">
							<div class="time-line-item-header flex space-between align-center">
								<p class="text-time">{{ formatCreateTime(item.createTime) }}</p>
								<div :class="item.approvalStatus == 3 ? 'text-error-tag' : 'text-success-tag'" v-if="item.statusLabel">{{ item.statusLabel }}</div>
							</div>
							<p class="text-title">{{ approvalHierarchyLabel[item.approvalHierarchy] ||item.createUserName }} </p>
							<p class="text-value">{{ item.approvalRemarks }}</p>
              <p class="text-value" v-if="item.currentApproval">节点审批人：{{ item.currentApprovalUserName }}</p>
              <FileList v-if="item.approvalImgs" :value="item.approvalImgs" class="mt10"/>
						</div>
					</div>
				</div>
			</el-scrollbar>
		</ApplyReport>
	</div>
</template>

<script setup lang="ts">
import apiMod from '@/apiMod/index'
import ApplyReport from '@/views/instOperate/apply/ReportDetail/index.vue'
import FileList from '@/views/aplid/DetailPage/ContentListItem/FileList/index.vue'
import { useDateFormat } from '@vueuse/core'
import { onMounted } from 'vue'

const props = defineProps<{
	nowRowData: any
}>()

const loading = ref(false)
const nowData: any = ref({})
const navTagList = [
	{ label: '机构填报内容（申请表）', value: 2 },
	{ label: '机构填报内容（床位审核表）', value: 4 },
	{ label: '机构申请需要上传的材料', value: 3 },
	{ label: '补贴回执', value: 5 },
]
const statusLabel = {
	'-1': '作废',
	'0': '待审批',
	'1': '审批中',
	'2': '通过',
	'3': '驳回',
}

const approvalHierarchyLabel = {
	'1': '社区',
	'2': '街道',
	'3': '区',
	'4': '市',
	'5': '第三方',
}
const lineTimeList = ref([])
const params:any  = ref({
  creditCode:''
})
const formatCreateTime = (time) => {
	const ntme = useDateFormat(time, 'YYYY年MM月DD日 HH:mm:ss')
	return ntme.value
}

const getInitData = () => {
	loading.value = true
	apiMod
		.view_ofsSubsidyFiling_view(props.nowRowData.id)
		.then((res) => {
			const data = res.data
			if (data.approvalJson && !Array.isArray(data.approvalJson)) {
				const tempData = JSON.parse(data.approvalJson) || []
				lineTimeList.value = tempData.map((item) => {
					return {
						...item,
						statusLabel: statusLabel[item.approvalStatus],
					}
				}).reverse().filter(item=>item.id)
			}
      params.value= {
        creditCode:data.creditCode,
        organizationId:'',
        belongDate:data.belongDate.replace('年','-').replace('月',''),
        subsidyProjectId:data.subsidyProjectId,
      }
			nowData.value = {
        fromId: data.fromId,
				tableRel: data.relTableResult,
				materialRel: data.relMaterialResult,
				dataRel: data.relDataResult,
				receiptListJson: data.receiptJson,
				allData:props.nowRowData // 将传过来的所有数据传入
			}
			loading.value = false
		})
		.catch(() => {
			loading.value = false
		})
}

onMounted(() => {
	getInitData()
})
</script>

<style scoped lang="scss">
@import '@/views/instOperate/components/styles/progress.scss';
</style>
